package com.wzdigit.wms.basic.service;

import com.wzdigit.framework.Shift;
import com.wzdigit.wms.basic.domain.permission.IfWearehourseKeeperDto;
import com.wzdigit.wms.basic.mapper.core.permission.IfWearehouseKeeperMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 物料组权限--服务类
 * 
 * @author Administrator
 *
 */
@Service
public class SkuPermService {

    @Autowired
	private IfWearehouseKeeperMapper ifWearehouseKeeperMapper;
    
	/**
	 * 获取指定用户权限的物料ID
	 * 
	 * @param userName
	 * @param whsIdList
	 * @return
	 */
	public List<Integer> getSkuIdPerm(String userName, List<Integer> whsIdList) {
		List<IfWearehourseKeeperDto> ifWearehourseKeeperList = ifWearehouseKeeperMapper.selectSkuIdByUser(userName, whsIdList);
		if (ifWearehourseKeeperList.size() == 0) {
			Shift.fatal("当前用户未维护权限物料！");
		}
		List<Integer> skuIdList = ifWearehourseKeeperList.stream().map(w -> w.getSKU_ID()).collect(Collectors.toList());
		return skuIdList;
	}

	//获取当前用户对应权限的EPR仓库
	public List<String> selectErpWhsByUser(String userName, List<Integer> whsIdList) {
		List<String> ifWearehourseKeeperList = ifWearehouseKeeperMapper.selectErpWhsByUser(userName, whsIdList);
		if (ifWearehourseKeeperList.size() == 0) {
			Shift.fatal("当前用户未维护权限仓库！");
		}
		return ifWearehourseKeeperList;
	}

}
